#include "ros/ros.h"
#include "turtlesim/Spawn.h"

int main(int argc, char *argv[])
{
    if(argc != 5)
    {
        ROS_ERROR("Usage: demo3_server name x y theta");
        return 1;
    }
    setlocale(LC_ALL, "");
    ros::init(argc, argv, "SpawnSrv");
    ros::NodeHandle nh;

    ros::ServiceClient client = nh.serviceClient<turtlesim::Spawn>("/spawn");
    // 等待服务启动
    client.waitForExistence();
    // 设置参数
    turtlesim::Spawn sp;
    sp.request.name = argv[1];
    sp.request.x = atof(argv[2]);
    sp.request.y = atof(argv[3]);
    sp.request.theta = atof(argv[3]);

    bool flag = client.call(sp);
    if(flag)
    {
        ROS_INFO("乌龟创建成功：%s", sp.response.name.c_str());
    }
    else
    {
        ROS_ERROR("乌龟创建失败！");
    }
    return 0;
}
